feat: adds HMAC authentication support for catalog remote#568
Conversation
Implements KMS-based HMAC authentication for catalog gRPC connections: - Add HMACAuthConfig to catalog configuration - Implement AWS KMS HMAC signature generation using SHA-256 - Add HMAC signature and timestamp to gRPC metadata headers - Refactor catalog stores to support HMAC-enabled DataAccess calls
🦋 Changeset detectedLatest commit: af656db The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
e743263 to
9911d95
Compare
|
|
||
| func (c *CatalogClient) DataAccess() (grpc.BidiStreamingClient[pb.DataAccessRequest, pb.DataAccessResponse], error) { | ||
| func (c *CatalogClient) DataAccess(req proto.Message) (grpc.BidiStreamingClient[pb.DataAccessRequest, pb.DataAccessResponse], error) { | ||
| if c.cachedStream == nil { |
There was a problem hiding this comment.
potential race condition here, maybe we can use sync.once
func (c *CatalogClient) DataAccess(req proto.Message) (grpc.BidiStreamingClient[pb.DataAccessRequest, pb.DataAccessResponse], error) {
c.streamInitOnce.Do(func() {
ctx := c.ctx
if c.hmacConfig != nil {
var err error
ctx, err = c.prepareHMACContext(c.ctx, req)
if err != nil {
c.streamInitErr = fmt.Errorf("failed to prepare HMAC context: %w", err)
return
}
}
stream, err := c.protoClient.DataAccess(ctx)
if err != nil {
c.streamInitErr = err
return
}
c.cachedStream = stream
})
return c.cachedStream, c.streamInitErr
}
There was a problem hiding this comment.
Good, point. I applied your suggestion!
| ctx := c.ctx | ||
| if c.hmacConfig != nil { | ||
| var err error | ||
| ctx, err = c.prepareHMACContext(c.ctx, req) |
There was a problem hiding this comment.
i noticed here in preparedHMACContext, it cals config.LoadDefaultConfig( everytime, which means if we start a new stream, it has to load the default config again, i wonder if we can just do that once too?
Just playing around, maybe a bad idea haha
// Initialize KMS client once
func (c *CatalogClient) getKMSClient(ctx context.Context) (kmsClient, error) {
c.kmsClientOnce.Do(func() {
cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion(c.hmacConfig.KeyRegion))
if err != nil {
c.kmsClientErr = fmt.Errorf("failed to load AWS config: %w", err)
return
}
c.kmsClient = kms.NewFromConfig(cfg)
})
return c.kmsClient, c.kmsClientErr
}
There was a problem hiding this comment.
Yeah we can write it so we ensure this runs only once. Looking at how we are using catalog client right now I don't think it would be ever loaded more than once but it's good for future upgrades
| if strings.Contains(streamErr.Error(), "Unauthenticated") || strings.Contains(streamErr.Error(), "HMAC") { | ||
| t.Skipf("Catalog service at %s requires HMAC authentication. Skipping integration test.", catalogAddr) |
There was a problem hiding this comment.
is using contains the best way we can check?I thought dimitrios did some work on the server returning some error code?
There was a problem hiding this comment.
but i guess since it is test, not super fuss if there is no better way
The interceptors slice was declared but never populated, making the conditional check and append operation dead code. This cleanup removes both the unused variable declaration and the unreachable code block.
| "catalog.auth.kms_key_id": {"CATALOG_AUTH_KMS_KEY_ID", "CATALOG_SERVICE_AUTH_KMS_KEY_ID"}, | ||
| "catalog.auth.kms_key_region": {"CATALOG_AUTH_KMS_KEY_REGION", "CATALOG_SERVICE_AUTH_KMS_KEY_REGION"}, |
There was a problem hiding this comment.
Why do we need the other ones? We should just need 1 value for each mapping ? The others have 2 because of backwards compatibility.
| "catalog.auth.kms_key_id": {"CATALOG_AUTH_KMS_KEY_ID", "CATALOG_SERVICE_AUTH_KMS_KEY_ID"}, | |
| "catalog.auth.kms_key_region": {"CATALOG_AUTH_KMS_KEY_REGION", "CATALOG_SERVICE_AUTH_KMS_KEY_REGION"}, | |
| "catalog.auth.kms_key_id": {"CATALOG_AUTH_KMS_KEY_ID"}, | |
| "catalog.auth.kms_key_region": {"CATALOG_AUTH_KMS_KEY_REGION"}, |
|
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## chainlink-deployments-framework@0.65.0 ### Minor Changes - [#568](#568) [`109b6f8`](109b6f8) Thanks [@giogam](https://github.com/giogam)! - feat: adds HMAC authentication support for catalog remote - [#559](#559) [`57ee135`](57ee135) Thanks [@ecPablo](https://github.com/ecPablo)! - Add support to decode proposals that use EIP-1967 proxies - [#562](#562) [`aa38817`](aa38817) Thanks [@jkongie](https://github.com/jkongie)! - Removes the import of a root `go.mod` from a scaffolded domain - [#567](#567) [`d06057a`](d06057a) Thanks [@JohnChangUK](https://github.com/JohnChangUK)! - Sui MCMS upgrade ### Patch Changes - [#530](#530) [`dc2c113`](dc2c113) Thanks [@graham-chainlink](https://github.com/graham-chainlink)! - fix: make config files and chain credentials optional --------- Co-authored-by: app-token-issuer-engops[bot] <144731339+app-token-issuer-engops[bot]@users.noreply.github.com>


Implements KMS-based HMAC authentication for catalog gRPC connections: